home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_9.zip / INT.H < prev    next >
C/C++ Source or Header  |  1992-10-05  |  14KB  |  389 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9.  
  10. /*    +---------------------------------------------------+
  11.       |                           |
  12.       |         I N T E R P     M A I N          |
  13.       |                           |
  14.       |           (C Version)              |
  15.       |                           |
  16.       |   Adapted From Low Level SETL version written by  |
  17.       |                           |
  18.       |          Monte Zweben              |
  19.       |           Philippe Kruchten           |
  20.       |           Jean-Pierre Rosen           |
  21.       |                           |
  22.       |    Original High Level SETL version written by      |
  23.       |                           |
  24.       |           Robert B. K. Dewar          |
  25.       |           Clint Goss              |
  26.       |           Tracey M. Siesser           |
  27.       |           Bernard D. Banner           |
  28.       |           Stephen C. Bryant           |
  29.       |          Gerry Fisher              |
  30.       |                           |
  31.       |          C version written by          |
  32.       |                           |
  33.       |           Robert B. K. Dewar          |
  34.       |                           |
  35.       +---------------------------------------------------+             */
  36.  
  37. #include <stdio.h>
  38.  
  39. /*  This module contains constants used in all parts of the interpretor */
  40.  
  41. /*
  42.  *  General use constants
  43.  *  ---------------------
  44.  */
  45.  
  46. #define VERSION            "9-25-85"           /* version identification */
  47. #define NB_REGISTERS       6
  48. #define ADA_MAX_REAL       8.507055E+37           /* maximum real with safety */
  49. #ifndef TRUE
  50. #define TRUE           1               /* boolean true = Ada true */
  51. #endif
  52. #ifndef FALSE
  53. #define FALSE           0               /* boolean false = Ada false */
  54. #endif
  55. #define MIN_LONG       ((long)0x80000000)           /* minimum fixed value */
  56. #define MAX_LONG       ((long)0x7fffffff)           /* maximum fixed value */
  57. #define ENDLESS        -1               /* value for endless delay */
  58. #define NULL_INT       ((int *)0)           /* null pointer value */
  59.  
  60. /* Special task values, note that OWNER_WAITING must be less than NULL_TASK
  61.  * when two task numbers are compared. This is required for correct functioning
  62.  * of the tasking code.
  63.  */
  64.  
  65. #define NULL_TASK       -1               /* null task pointer value */
  66. #define OWNER_WAITING       -2               /* minimum fixed value */
  67.  
  68. /* Mask for stack access = MAX_TASKS - 1.
  69.  * Note that MAX_TASKS must be a power of two.
  70.  */
  71.  
  72. #define TMASK              0177
  73.  
  74. /* Default Values */
  75.  
  76. #define SECURITY_LEVEL 50 /* free words in the stack before calls */
  77. #define TASK_CODE_OFFSET 4 /* starting offset in code segment for task */
  78.  
  79. /* Size of long and float values in words (ints) */
  80.  
  81. #define WORDS_FLOAT (sizeof(float)/sizeof(int))
  82. #define WORDS_LONG   (sizeof(long)/sizeof(int))
  83. #define WORDS_PTR  (sizeof(int *)/sizeof(int))
  84. /* WORDS_HDR is number of words in header of heap block */
  85. #define WORDS_HDR  (1 + WORDS_PTR)
  86.  
  87. /* Definition of a stack frame */
  88.  
  89. #define SF_PREVIOUS_SFP          0
  90. #define SF_RETURN_CS             1
  91. #define SF_RETURN_IP             2
  92.  
  93. /* Definition of exceptions */
  94.  
  95. #define CONSTRAINT_ERROR         1
  96. #define NUMERIC_ERROR             1
  97. #define PROGRAM_ERROR             3
  98. #define STORAGE_ERROR             4
  99. #define TASKING_ERROR             5
  100. #define SYSTEM_ERROR             6
  101. /* these come from predef and not be defined here */
  102. #define STATUS_ERROR             7
  103. #define MODE_ERROR             8
  104. #define NAME_ERROR             9
  105. #define USE_ERROR             10
  106. #define DEVICE_ERROR             11
  107. #define END_ERROR             12
  108. #define DATA_ERROR             13
  109. #define LAYOUT_ERROR             14
  110. #define TIME_ERROR             15
  111.  
  112. /* Attributes */
  113.  
  114. /* Those attributes marked "static" are treated by the front end and do not
  115.  * appear as arguments to the attribute instruction. Note that POS and VAL
  116.  * are not static, but do not appear as attribute instruction arguments
  117. Static:
  118. A_AFT ATTR_BASE ATTR_DELTA ATTR_DIGITS ATTR_EMAX ATTR_EPSILON ATTR_FIRST_BIT
  119. ATTR_MACHINE_EMAX ATTR_MACHINE_EMIN ATTR_MACHINE_MANTISSA
  120. ATTR_MACHINE_OVERFLOWS ATTR_MACHINE_RADIX ATTR_MACHINE_ROUNDS
  121. ATTR_POS       -- not static but generates nothing
  122. ATTR_SAFE_EMAX ATTR_SAFE_LARGE ATTR_SAFE_SMALL
  123. ATTR_SMALL ATTR_STORAGE_SIZE(?)
  124. ATTR_VAL --not static but generate a qual_range
  125.  */
  126. #include "attr.h"
  127. #include "ops.h"
  128.  
  129.  
  130. /* General Addressing Macros */
  131.  
  132. /*
  133.  *  LONG(ptr)        Pointer regarded as pointer to long value
  134.  *  ADDR(ds,off)    Get address from data seg offset values
  135.  *  ADDRL(ds,off)    Get address of long from data seg offset values
  136.  *  POP(val)        Pop int val off stack
  137.  *  POPF(fval)        Pop float fval off stack
  138.  *  POPL(lval)        Pop long lvall off stack
  139.  *  POPP(lval)        Pop pointer from stack
  140.  *  POP_ADDR(bs,of)    Pop base/offset address from stack
  141.  *  POP_PTR(ptr)    Pop pointer from stack
  142.  *  PUSH(val)        Push int val onto stack
  143.  *  PUSHF(fval)        Push float fval onto stack
  144.  *  PUSHL(lval)        Push long lval onto stack (also used for fixed)
  145.  *  PUSHP(lval)        Push pointer onto stack
  146.  *  PUSH_ADDR(bs,of)    Push address onto stack
  147.  *  TOS            Reference top of stack as int
  148.  *  TOSF        Reference top of stack as float
  149.  *  TOSL        Reference top of stack as long
  150.  *  TOSM(n)        Reference n'th item from top (TOS = TOSM(0))
  151.  *  BLOCK_FRAME        Pointer to the current block frame
  152.  *  STACK_FRAME(dsp)    Access an element from the current stack frame
  153.  */
  154.  
  155.  
  156. #define LONG(ptr)      ((long *)(ptr))
  157. #define ADDR(ds,off)      (data_segments[ds] + off)
  158. #define ADDRL(ds,off)      (LONG(data_segments[ds] + off))
  159. #define POP(val)      val=cur_stack[cur_stackptr--]
  160. #define POPF(fval)      fval = TOSF,cur_stackptr -= WORDS_FLOAT
  161. #define POPL(lval)      lval = TOSL,cur_stackptr -= WORDS_LONG
  162. #define POPP(lval)      POPL((long)lval)
  163. #define POP_ADDR(bs,of)   POP(of),POP(bs)
  164. #define POP_PTR(pt)       pt=ADDR(TOSM(1),TOS),cur_stackptr -= 2
  165. #define PUSH(val)      cur_stack[++cur_stackptr] = val
  166. #define PUSHF(fval)      cur_stackptr+=WORDS_FLOAT,TOSF=fval
  167. #define PUSHL(lval)      cur_stackptr+=WORDS_FLOAT,TOSL=lval
  168. #define PUSHP(lval)      PUSHL((long)lval)
  169. #define PUSH_ADDR(bs,of)  PUSH(bs),PUSH(of)
  170. #define TOS          (cur_stack[cur_stackptr])
  171. #define TOSF          *((float *)(cur_stack+cur_stackptr+1-WORDS_FLOAT))
  172. #define TOSL          *(LONG(cur_stack+cur_stackptr+1-WORDS_LONG))
  173. #define TOSML(n)      *(LONG(cur_stack+cur_stackptr+1-((n)+1)*WORDS_LONG))
  174. #define TOSM(n)       (cur_stack[cur_stackptr-(n)])
  175. #define BLOCK_FRAME      ((struct bf *)(cur_stack+bfp))
  176. #define ARB_BLOCK_FRAME(t,b) ((struct bf *)((STACK(t))+(b)))
  177. #define STACK_FRAME(dsp)  cur_stack[sfp+dsp]
  178.  
  179. /* Macros for accessing fields of block frame */
  180.  
  181. #define BF_PREVIOUS_BFP(t,b)     (ARB_BLOCK_FRAME(t,b))->bf_previous_bfp
  182. #define BF_DATA_LINK(t,b)     (ARB_BLOCK_FRAME(t,b))->bf_data_link
  183. #define BF_TASKS_DECLARED(t,b)     (ARB_BLOCK_FRAME(t,b))->bf_tasks_declared
  184. #define BF_SUBTASKS(t,b)     (ARB_BLOCK_FRAME(t,b))->bf_subtasks
  185. #define BF_HANDLER(t,b)     (ARB_BLOCK_FRAME(t,b))->bf_handler
  186. #define BF_NUM_NOTERM(t,b)     (ARB_BLOCK_FRAME(t,b))->bf_num_noterm
  187. #define BF_NUM_DEPS(t,b)     (ARB_BLOCK_FRAME(t,b))->bf_num_deps
  188.  
  189. #define MY_PREVIOUS_BFP          (BLOCK_FRAME)->bf_previous_bfp
  190. #define MY_DATA_LINK          (BLOCK_FRAME)->bf_data_link
  191. #define MY_TASKS_DECLARED    (BLOCK_FRAME)->bf_tasks_declared
  192. #define MY_SUBTASKS              (BLOCK_FRAME)->bf_subtasks
  193. #define MY_HANDLER              (BLOCK_FRAME)->bf_handler
  194. #define MY_BF_NUM_NOTERM    (BLOCK_FRAME)->bf_num_noterm
  195. #define MY_BF_NUM_DEPS        (BLOCK_FRAME)->bf_num_deps
  196.  
  197. /* Utility Macros */
  198.  
  199. #define ABS(v)          ((v) >= 0 ? (v) : -(v))
  200. #define BOOL(v)       ((v) % 2)
  201. #define MAX(a,b)      (((a) >= (b)) ? (a) : (b))
  202. #define MIN(a,b)      (((a) <= (b)) ? (a) : (b))
  203. #define SIGN(a)       (((a) > 0) - ((a) < 0))
  204.  
  205.  
  206. /* Block Frame */
  207.  
  208.    struct bf {
  209.       int      bf_previous_bfp;    /* offset to previous block frame */
  210.       int     *bf_data_link;     /* head of chain of data blocks */
  211.       int     *bf_tasks_declared;    /* head of chain of created tasks */
  212.       int      bf_num_noterm;    /* number of non terminated */
  213.       int      bf_num_deps;        /* number of non terminated */
  214.       int      bf_subtasks;        /* head of chain of dependent tasks */
  215.       int      bf_handler;        /* IP of exception handler */
  216.    };
  217.  
  218. /** NEW TYPES **/
  219.  
  220. /* Item Type for Multi-Queues */
  221.  
  222.    struct rts_item {
  223.       int      mult, save_mult;    /* multiplicity count             */
  224.       int      parent;            /* parent tcb index               */
  225.       int      *tcbs;            /* array of tcb nums of new tasks */
  226.       int      type;                /* action - create or activate    */
  227.       int      prio;                 /* priority